package com.chat.datea.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.MusicList;

import java.util.ArrayList;

/**
 * Created by YanBinXie on 15/10/30.
 */
public class PupWindow_ListView_Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<MusicList> lists;
    private  int positi;

    public PupWindow_ListView_Adapter(Context context, ArrayList<MusicList> lists, int position) {
        this.context = context;
        this.lists = lists;
        positi = position;

    }
    public void addPosition(int position){
        positi = position;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return lists != null && lists.size() > 0 ? lists.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return lists != null && lists.size() > 0 ? getItem(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return lists != null && lists.size() > 0 ? position : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.pupwindow_item, null);
            holder.music_name = (TextView) convertView.findViewById(R.id.music_name);
            holder.music_singer = (TextView) convertView.findViewById(R.id.music_singer);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.music_name.setText(lists.get(position).getName());
        holder.music_singer.setText(lists.get(position).getSinger());
        if (positi == position) {
            holder.music_name.setTextColor(Color.RED);
            holder.music_singer.setTextColor(Color.RED);

        } else {
            holder.music_name.setTextColor(Color.BLACK);
            holder.music_singer.setTextColor(Color.BLACK);
        }
        notifyDataSetChanged();
        return convertView;
    }

    private class ViewHolder {
        TextView music_singer, music_name;
    }
}
